
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @module http.core
* @author: Hjava
* @description: HTTP模块基础核心方法
* @since: 2018-07-22 15:26:42
*/
var eventEmitter_1 = __webpack_require__(/*! _util/eventEmitter */ "./src/core/utils/eventEmitter.ts");
var axios_1 = __webpack_require__(/*! axios */ "./node_modules/axios/index.js");
var protocol_1 = __webpack_require__(/*! _util/protocol */ "./src/core/utils/protocol.ts");
var http_config_1 = __webpack_require__(/*! _http/http.config */ "./src/core/http/http.config.ts");
var constant_1 = __webpack_require__(/*! _util/constant */ "./src/core/utils/constant.ts");
var analytics_1 = __webpack_require__(/*! _util/analytics */ "./src/core/utils/analytics.ts");
var byteBuffer_1 = __webpack_require__(/*! _util/byteBuffer */ "./src/core/utils/byteBuffer.ts");
var uuid_1 = __webpack_require__(/*! _util/uuid */ "./src/core/utils/uuid.ts");
var typeChecker_1 = __webpack_require__(/*! _util/typeChecker */ "./src/core/utils/typeChecker.ts");
var constant_2 = __webpack_require__(/*! _util/constant */ "./src/core/utils/constant.ts");
var isIE_1 = __webpack_require__(/*! _util/isIE */ "./src/core/utils/isIE.ts");
var log_1 = __webpack_require__(/*! ./../utils/log */ "./src/core/utils/log.ts");
var constant_3 = __webpack_require__(/*! _util/constant */ "./src/core/utils/constant.ts");
var index_1 = __webpack_require__(/*! ./../worker/index */ "./src/core/worker/index.ts");
var worker_const_1 = __webpack_require__(/*! ./../worker/worker-const */ "./src/core/worker/worker-const.js");
var long_1 = __webpack_require__(/*! _util/long */ "./src/core/utils/long.ts");
var userData_1 = __webpack_require__(/*! _util/userData */ "./src/core/utils/userData.ts");
var proxyPath = '';
var headers = {};
var proxy = false;
var defaultDomain = null;
var env = constant_2.ENV.ONLINE;
var beforeSendCallback = function () {
    return {
        headers: null,
        data: null,
        query: null
    };
};
exports.default = {
    setHeader: function (header1) {
        headers = header1;
    },
    setBeforeSendCallback: function (callback) {
        beforeSendCallback = callback;
    },
    /**
     * @param env 坏境字符串
     * @param opts 额外配置参数
     */
    setEnv: function (httpEnv, opts) {
        if (httpEnv === void 0) { httpEnv = constant_2.ENV.ONLINE; }
        if (opts === void 0) { opts = {}; }
        var httpConfig = http_config_1.default();
        if (httpEnv !== constant_2.ENV.ONLINE && httpEnv !== constant_2.ENV.ST && httpEnv !== constant_2.ENV.TEST) {
            httpEnv = constant_2.ENV.ONLINE;
        }
        httpConfig[httpEnv] = __assign(__assign({}, httpConfig[httpEnv]), opts);
        env = httpEnv;
    },
    getEnv: function () {
        return env;
    },
    setDefaultDomain: function (domain) {
        defaultDomain = domain;
    },
    /**
     * @param url {string} 请求url
     * @param options {object} 请求参数 contains:
     * #proxy {boolean}
     * #data {object} params
     * #type {boolean} Override method type if needed.if 'type' variable is undefined, then 'POST' method will be used
     * #success {function} callback
     * #error {function} callback
     * 发送http请求
     */
    request: function (url, options, withoutHeader) {
        if (url === void 0) { url = ''; }
        if (!headers && !withoutHeader) {
            return false;
        }
        if (!url) {
            return false;
        }
        options.url = url;
        options.proxy = options.proxy || proxy;
        this._send(options);
        return true;
    },
    /**
     * 获取代理路径
     * @return {string}
     */
    getProxyPath: function () {
        return proxyPath;
    },
    /**
     * 设置代理路径
     * @param newProxyPath 新的代理路径
     */
    setProxyPath: function (newProxyPath) {
        proxyPath = newProxyPath;
    },
    /**
     * 根据options参数发送请求
     * @param options {!object}
     * @private
     */
    _send: function (options) {
        var url = options.url;
        var proxy = options.proxy;
        var type = options.type || 'POST';
        var data = options.data || {};
        var success = options.success;
        var error = options.error;
        var timeout = options.timeout || 30000;
        var httpConfig = http_config_1.default();
        var config = httpConfig[env];
        var requestId = uuid_1.default.next();
        if (defaultDomain) {
            url = defaultDomain + url;
        }
        else if (!proxy) {
            var paths = url.match(/^\/\w+/g);
            var i = 0;
            var router = config.routerMap;
            while (paths[i]) {
                router = router[paths[i++]];
                if (typeof router === 'string') {
                    break;
                }
                else if (!router) {
                    break;
                }
            }
            if (typeof router !== 'string') {
                router = config.routerMap['host'];
            }
            if (isIE_1.default) {
                var router1 = this.getProxyPath();
                if (router1) {
                    router = /\/$/.test(router1) ? router1 : router1 + '/';
                }
            }
            url = router + url;
        }
        else {
            url = '/proxy' + url;
        }
        //允许自定义header
        var httpHeaders = headers;
        if (options.headers) {
            httpHeaders = __assign(__assign({}, httpHeaders), options.headers);
        }
        if (type === 'POST') {
            httpHeaders['Content-Type'] = options.formData ? false : 'application/json';
        }
        // 允许每次发请求前，通过beforeSendCallback来改变header和data
        if (typeChecker_1.default.isFunction(beforeSendCallback)) {
            var beforeSendCallbackResult = beforeSendCallback();
            var callbackHeaders = beforeSendCallbackResult.headers;
            var callbackData = beforeSendCallbackResult.data;
            var callbackQuery = beforeSendCallbackResult.query;
            if (typeChecker_1.default.isObject(callbackHeaders)) {
                httpHeaders = __assign(__assign({}, httpHeaders), callbackHeaders);
            }
            if (typeChecker_1.default.isObject(callbackData)) {
                data = __assign(__assign({}, data), callbackData);
            }
            if (typeChecker_1.default.isObject(callbackQuery)) {
                var queueString = '';
                for (var i_1 in callbackQuery) {
                    queueString += i_1 + '=' + callbackQuery[i_1];
                }
                // 目前SDK中所有的url都是没有queue和hash的，因此可以采用此方法来进行添加，后续添加url时需要确认此处逻辑
                url += '?' + queueString;
            }
        }
        if (typeof url === 'string') {
            data = JSON.stringify(data);
            if (type === 'GET') {
                data = '';
            }
            if (false) {}
            else if (false) {}
            else {
                axios_1.default({
                    url: url,
                    method: type,
                    headers: proxy ? {} : httpHeaders,
                    data: data,
                    timeout: timeout
                }).then(function (response) {
                    var data = response.data;
                    var valObject = {
                        url: url,
                        code: data && data.rescode !== void 0 ? data.rescode : -123456,
                        id: requestId
                    };
                    // Log.log('HttpCore::_send success info:' + JSON.stringify(valObject))
                    analytics_1.default.report({
                        nm: 'send_request_success',
                        val: valObject
                    });
                    success && success(data, response);
                }).catch(function (e) {
                    var valObject = {
                        url: url,
                        id: requestId
                    };
                    // Log.error('HttpCore::_send fail info:' + JSON.stringify(valObject) + " errorData:" + e)
                    analytics_1.default.report({
                        nm: 'send_request_fail',
                        val: valObject
                    });
                    if (error) {
                        error(e);
                    }
                });
            }
            var valObject = {
                url: url,
                data: JSON.stringify(data),
                id: requestId
            };
            // Log.log('HttpCore::_send info:' + JSON.stringify(valObject))
            analytics_1.default.report({
                nm: 'send_request',
                val: valObject
            });
        }
    },
    /**
     * 获取离线消息接口
     * @param url 获取离线消息url
     * @param options 获取离线消息参数
     * @private
     */
    _offline: function (url, options, fromSource) {
        if (url === void 0) { url = ''; }
        //callback fun success must be provided
        var _suc = options.success;
        var _error = options.error;
        options.data.u = headers.u;
        options.data.ai = headers.ai;
        options.data.dt = headers.dt;
        options.success = function (res) {
            var mids = [];
            if (res.rescode === 0) {
                var data = res.data['res'];
                var msgs = [];
                for (var i = 0; i < data.length; i++) {
                    try {
                        data[i] = protocol_1.default.Response.fromBase64(data[i]);
                        for (var j = 0; j < data[i].msgs.length; j++) {
                            msgs.push(data[i].msgs[j]);
                            try {
                                mids.push(data[i].msgs[j].msgId ? data[i].msgs[j].msgId.toString() : '');
                            }
                            catch (e) {
                                log_1.default.log('offline 统计异常,不影响正常逻辑 exception:' + e);
                            }
                        }
                    }
                    catch (e) {
                        log_1.default.error('~~~~~offline 解析失败，当前原始数据 exception:' + e);
                        log_1.default.error(data[i]);
                    }
                }
                if (msgs.length && !options.noAck) {
                    if (options.data.svid === 401) {
                        eventEmitter_1.default.emit('__IMAck', msgs);
                    }
                    else {
                        eventEmitter_1.default.emit('__PubAck', msgs);
                    }
                }
            }
            _suc(res);
            switch (fromSource) {
                case constant_1.LOG_FROM_SOURCE.CHAT: {
                    analytics_1.default.report({
                        nm: 'message_fetch_chat_offline_success',
                        val: {
                            count: mids.length,
                            mids: mids
                        }
                    });
                    break;
                }
                case constant_1.LOG_FROM_SOURCE.GROUP: {
                    analytics_1.default.report({
                        nm: 'message_fetch_group_offline_success',
                        val: {
                            count: mids.length,
                            mids: mids
                        }
                    });
                    break;
                }
                case constant_1.LOG_FROM_SOURCE.PUB: {
                    analytics_1.default.report({
                        nm: 'message_fetch_pub_offline_success',
                        val: {
                            count: mids.length,
                            mids: mids
                        }
                    });
                    break;
                }
            }
        };
        options.error = function (e) {
            _error && _error(e);
            switch (fromSource) {
                case constant_1.LOG_FROM_SOURCE.CHAT: {
                    analytics_1.default.report({
                        nm: 'message_fetch_chat_offline_error',
                        val: {
                            code: e && e.request && e.request.status ? e.request.status : void 0
                        }
                    });
                    break;
                }
                case constant_1.LOG_FROM_SOURCE.GROUP: {
                    analytics_1.default.report({
                        nm: 'message_fetch_group_offline_error',
                        val: {
                            code: e && e.request && e.request.status ? e.request.status : void 0
                        }
                    });
                    break;
                }
                case constant_1.LOG_FROM_SOURCE.PUB: {
                    analytics_1.default.report({
                        nm: 'message_fetch_pub_offline_error',
                        val: {
                            code: e && e.request && e.request.status ? e.request.status : void 0
                        }
                    });
                    break;
                }
            }
        };
        this.request(url, options);
        switch (fromSource) {
            case constant_1.LOG_FROM_SOURCE.CHAT: {
                analytics_1.default.report('message_fetch_chat_offline_start');
                break;
            }
            case constant_1.LOG_FROM_SOURCE.GROUP: {
                analytics_1.default.report('message_fetch_group_offline_start');
                break;
            }
            case constant_1.LOG_FROM_SOURCE.PUB: {
                analytics_1.default.report('message_fetch_pub_offline_start');
                break;
            }
        }
    },
    /**
     * 获取离线消息接口
     * @param url 获取离线消息url
     * @param options 获取离线消息参数
     * @private
     */
    _dataOffline: function (url, options, fromSource) {
        if (url === void 0) { url = ''; }
        //callback fun success must be provided
        var _suc = options.success;
        var _error = options.error;
        options.data.u = headers.u;
        options.data.ai = headers.ai;
        options.data.dt = headers.dt;
        options.success = function (res) {
            var mids = [];
            if (res.rescode === 0) {
                var data = res.data['res'];
                var msgs = [];
                for (var i = 0; i < data.length; i++) {
                    try {
                        data[i] = protocol_1.default.Response.fromBase64(data[i]);
                        for (var j = 0; j < data[i].msgs.length; j++) {
                            var buffer = data[i].msgs[j].data;
                            try {
                                data[i].msgs[j].data = (new byteBuffer_1.default(buffer)).readUTF8String(buffer.byteLength);
                            }
                            catch (e) {
                                // 尝试解析失败时直接传递原始数据
                                // Log.error('_dataOffline error info:' + e)
                            }
                            msgs.push(data[i].msgs[j]);
                        }
                    }
                    catch (e) {
                        log_1.default.error('~~~~~offline 解析失败，当前原始数据');
                        log_1.default.error(data[i]);
                    }
                }
                eventEmitter_1.default.emit(constant_3.MESSAGE_EVENT.D_MESSAGE_OFFLINE, msgs);
            }
            _suc(res);
            var valObject = {
                url: url,
                count: mids.length,
                mids: mids
            };
            log_1.default.log('HttpCore::_dataOffline success info:' + JSON.stringify(valObject));
            analytics_1.default.report({
                nm: 'message_fetch_data_offline_success',
                val: valObject
            });
        };
        options.error = function (e) {
            log_1.default.error('HttpCore::_dataOffline fail info:' + e);
            _error && _error(e);
            analytics_1.default.report({
                nm: 'message_fetch_data_offline_error',
                val: {
                    code: e && e.request && e.request.status ? e.request.status : void 0
                }
            });
        };
        this.request(url, options);
        log_1.default.log('HttpCore::_dataOffline uid:' + headers.u + ' appId:' + headers.ai);
        analytics_1.default.report('message_fetch_data_offline_start');
    },
    /**
     * 获取历史消息接口
     * @param url 获取历史消息url
     * @param options 获取历史消息参数
     * @private
     */
    _history: function (url, options, fromSource) {
        if (url === void 0) { url = ''; }
        var startTime = Date.now();
        var _suc = options.success;
        var _error = options.error;
        options.data.u = headers.u;
        options.data.ai = headers.ai;
        var parseBase64HistoryMessages = function (data) {
            if (data === void 0) { data = null; }
            if (!data) {
                return;
            }
            for (var i = 0; i < data.length; i++) {
                try {
                    data[i] = protocol_1.default.Response.fromBase64(data[i]);
                }
                catch (e) {
                    console.error('parseMessages fail error:' + e + ' item:' + data[i]);
                }
            }
            return data;
        };
        var notifyHistoryRes = function (res) {
            var mids = [];
            if (res.rescode === 0) {
                var data = res.data['res'];
                for (var i = 0; i < data.length; i++) {
                    try {
                        try {
                            mids = mids.concat(data[i].msgs.map(function (m) {
                                return m && m.msgId ? long_1.default.fromValue(m.msgId).value() : '';
                            }));
                        }
                        catch (e) {
                            log_1.default.error('history 统计异常,不影响正常逻辑 info:' + e);
                        }
                    }
                    catch (e) {
                        log_1.default.error('~~~~~history 解析失败，当前原始数据 info:' + e + " item:" + data[i]);
                    }
                }
            }
            _suc(res);
            switch (fromSource) {
                case constant_1.LOG_FROM_SOURCE.CHAT: {
                    analytics_1.default.report({
                        nm: 'message_fetch_chat_history_success',
                        val: {
                            time: Date.now() - startTime,
                            chat: options && options.data && options.data.bs && options.data.bs[0] ? options.data.bs[0].b : '0',
                            count: mids.length,
                            mids: mids
                        }
                    });
                    break;
                }
                case constant_1.LOG_FROM_SOURCE.GROUP: {
                    analytics_1.default.report({
                        nm: 'message_fetch_group_history_success',
                        val: {
                            time: Date.now() - startTime,
                            chat: options && options.data && options.data.bs && options.data.bs[0] ? options.data.bs[0].b : '0',
                            count: mids.length,
                            mids: mids
                        }
                    });
                    break;
                }
                case constant_1.LOG_FROM_SOURCE.PUB: {
                    analytics_1.default.report({
                        nm: 'message_fetch_pub_history_success',
                        val: {
                            time: Date.now() - startTime,
                            chat: options && options.data && options.data.ps && options.data.ps[0] ? options.data.ps[0].u : '0',
                            count: mids.length,
                            mids: mids
                        }
                    });
                    break;
                }
            }
        };
        var syncParseData = function (res) {
            res.data['res'] = parseBase64HistoryMessages(res.data['res']);
            notifyHistoryRes(res);
        };
        var loadMsgParseWorkerFile = function () {
            var ret = null;
            try {
                ret = ( false) ? undefined : null;
                return ret;
            }
            catch (error) {
                log_1.default.error("HttpCore::_history loadMsgParseWorkerFile error:" + error);
            }
            return ret;
        };
        var workerParseData = function (res) {
            var workerTimeoutTime = userData_1.default.get('runHistoryWorkerTimeoutTime') ? userData_1.default.get('runHistoryWorkerTimeoutTime') : worker_const_1.HISTORY_MSG_WORKER_CONST.TIMEOUT;
            index_1.default.request({
                workerFile: loadMsgParseWorkerFile(),
                data: {
                    data: res.data['res'],
                    workerUserData: {
                        uid: userData_1.default.get('uid') || '',
                        appId: userData_1.default.get('appId') || 0,
                        deviceId: userData_1.default.get('deviceId') || '',
                    },
                },
                resCallback: function (workerRes) {
                    log_1.default.log('HttpCore::_history workerParseData result code:' + workerRes.code);
                    if (workerRes.code == worker_const_1.RESCODE.SUCCESS) {
                        res.data['res'] = workerRes.data;
                        notifyHistoryRes(res);
                    }
                    else {
                        syncParseData(res);
                    }
                },
                timeoutTime: workerTimeoutTime,
            });
        };
        options.success = function (res) {
            if (res.rescode === 0) {
                var runWorkerMaxMessageCount = userData_1.default.get('runHistoryWorkerMessageCount') ? userData_1.default.get('runHistoryWorkerMessageCount') : worker_const_1.HISTORY_MSG_WORKER_CONST.RUN_WORKER_BASE64_COUNT;
                if (false) {}
                else {
                    syncParseData(res);
                }
            }
            else {
                notifyHistoryRes(res);
            }
        };
        options.error = function (e) {
            _error && _error(e);
            switch (fromSource) {
                case constant_1.LOG_FROM_SOURCE.CHAT: {
                    analytics_1.default.report({
                        nm: 'message_fetch_chat_history_error',
                        val: {
                            chat: options && options.data && options.data.bs && options.data.bs[0] ? options.data.bs[0].b : '0',
                            code: e && e.request && e.request.status ? e.request.status : void 0
                        }
                    });
                    break;
                }
                case constant_1.LOG_FROM_SOURCE.GROUP: {
                    analytics_1.default.report({
                        nm: 'message_fetch_group_history_error',
                        val: {
                            chat: options && options.data && options.data.bs && options.data.bs[0] ? options.data.bs[0].b : '0',
                            code: e && e.request && e.request.status ? e.request.status : void 0
                        }
                    });
                    break;
                }
                case constant_1.LOG_FROM_SOURCE.PUB: {
                    analytics_1.default.report({
                        nm: 'message_fetch_pub_history_error',
                        val: {
                            chat: options && options.data && options.data.ps && options.data.ps[0] ? options.data.ps[0].u : '0',
                            code: e && e.request && e.request.status ? e.request.status : void 0
                        }
                    });
                    break;
                }
            }
        };
        this.request(url, options);
        switch (fromSource) {
            case constant_1.LOG_FROM_SOURCE.CHAT: {
                analytics_1.default.report({
                    nm: 'message_fetch_chat_history_start',
                    val: {
                        chat: options && options.data && options.data.bs && options.data.bs[0] ? options.data.bs[0].b : '0'
                    }
                });
                break;
            }
            case constant_1.LOG_FROM_SOURCE.GROUP: {
                analytics_1.default.report({
                    nm: 'message_fetch_group_history_start',
                    val: {
                        chat: options && options.data && options.data.bs && options.data.bs[0] ? options.data.bs[0].b : '0'
                    }
                });
                break;
            }
            case constant_1.LOG_FROM_SOURCE.PUB: {
                analytics_1.default.report({
                    nm: 'message_fetch_pub_history_start',
                    val: {
                        chat: options && options.data && options.data.ps && options.data.ps[0] ? options.data.ps[0].u : '0'
                    }
                });
                break;
            }
        }
    },
    _chatlist: function (url, options) {
        if (url === void 0) { url = ''; }
        var _suc = options.success;
        var _error = options.error;
        options.data.u = headers.u;
        options.data.ai = headers.ai;
        options.data.svid = 401;
        options.success = function (res) {
            var mids = [];
            if (res.rescode === 0) {
                var data = res.data['res'];
                for (var i = 0; i < data.length; i++) {
                    try {
                        data[i] = protocol_1.default.Response.fromBase64(data[i]);
                        try {
                            mids = mids.concat(data[i].msgs.map(function (m) {
                                return m && m.msgId ? m.msgId.toString() : '';
                            }));
                        }
                        catch (e) {
                            log_1.default.error('chatlist 统计异常,不影响正常逻辑 info:' + e);
                        }
                    }
                    catch (e) {
                        log_1.default.error('~~~~~chatlist 解析失败，当前原始数据 info:' + e);
                        log_1.default.error(data[i]);
                    }
                }
            }
            _suc(res);
            analytics_1.default.report({
                nm: 'message_im_sessionlist_success',
                val: {
                    url: url,
                    count: mids.length,
                    mids: mids
                }
            });
        };
        options.error = function (e) {
            _error && _error(e);
            analytics_1.default.report({
                nm: 'message_im_sessionlist_error',
                val: {
                    code: e && e.request && e.request.status ? e.request.status : void 0
                }
            });
        };
        this.request(url, options);
        analytics_1.default.report({
            nm: 'message_im_sessionlist_start',
            val: {
                url: url
            }
        });
    },
    /**
     * Pub远端会话列表获取
     * @param url 远端会话列表获取url
     * @param options 远端会话列表获取参数
     * @private
     */
    _pubChatlist: function (url, options) {
        if (url === void 0) { url = ''; }
        var _suc = options.success;
        var _error = options.error;
        options.data.u = headers.u;
        options.data.ai = headers.ai;
        options.success = function (res) {
            var mids = [];
            if (res.rescode === 0) {
                var data = res.data;
                var messages = data ? data.res : [];
                if (messages.length) {
                    for (var i = 0; i < messages.length; i++) {
                        try {
                            messages[i] = protocol_1.default.Response.fromBase64(messages[i]);
                            try {
                                mids = mids.concat(messages[i].msgs.map(function (m) {
                                    return m && m.msgId ? m.msgId.toString() : '';
                                }));
                            }
                            catch (e) {
                                log_1.default.log('pubChatlist 统计异常,不影响正常逻辑 info:' + e);
                            }
                        }
                        catch (e) {
                            log_1.default.error('~~~~~history  解析失败，当前原始数据 info:' + e);
                            log_1.default.error(data[i]);
                        }
                    }
                }
            }
            _suc(res);
            analytics_1.default.report({
                nm: 'message_pub_sessionlist_success',
                val: {
                    url: url,
                    count: mids.length,
                    mids: mids
                }
            });
        };
        options.error = function (e) {
            _error && _error(e);
            analytics_1.default.report({
                nm: 'message_pub_sessionlist_error',
                val: {
                    code: e && e.request && e.request.status ? e.request.status : void 0
                }
            });
        };
        this.request(url, options);
        analytics_1.default.report({
            nm: 'message_pub_sessionlist_start',
            val: {
                url: url
            }
        });
    },
    /**
     * Pub远端会话列表获取,通过最近消息的新接口
     * @param url 远端会话列表获取url
     * @param options 远端会话列表获取参数
     * @private
     */
    _pubChatListFromRecentMessages: function (url, options) {
        if (url === void 0) { url = ''; }
        var _suc = options.success;
        var _error = options.error;
        options.data.ai = headers.ai;
        options.success = function (res) {
            var data = res.data;
            var messages = data ? data.res : [];
            var mids = [];
            if (messages.length) {
                for (var i = 0; i < messages.length; i++) {
                    try {
                        messages[i] = protocol_1.default.Response.fromBase64(messages[i]);
                        try {
                            mids = mids.concat(messages[i].msgs.map(function (m) {
                                return m && m.msgId ? m.msgId.toString() : '';
                            }));
                        }
                        catch (e) {
                            log_1.default.log('pubChatlist 统计异常,不影响正常逻辑 info:' + e);
                        }
                    }
                    catch (e) {
                        log_1.default.error('~~~~~history  解析失败，当前原始数据 info:' + e);
                        log_1.default.error(data[i]);
                    }
                }
            }
            _suc(res);
            analytics_1.default.report({
                nm: 'message_pub_sessionlist_success',
                val: {
                    url: url,
                    count: mids.length,
                    mids: mids
                }
            });
        };
        options.error = function (e) {
            _error && _error(e);
            analytics_1.default.report({
                nm: 'message_pub_sessionlist_error',
                val: {
                    code: e && e.request && e.request.status ? e.request.status : void 0
                }
            });
        };
        this.request(url, options);
        analytics_1.default.report({
            nm: 'message_pub_sessionlist_start',
            val: {
                url: url
            }
        });
    },
    /**
     * 获取KEFU C端远端会话列表
     * @param url 远端会话列表获取url
     * @param options 远端会话列表获取参数
     * @private
     */
    _kefuChatlist: function (url, options) {
        if (url === void 0) { url = ''; }
        var _suc = options.success;
        var _error = options.error;
        options.data.u = headers.u;
        options.data.ai = headers.ai;
        options.success = function (res) {
            var data = res.data;
            var chatlist = data ? data.chatlist : [];
            if (chatlist.length) {
                for (var i = 0; i < chatlist.length; i++) {
                    try {
                        chatlist[i] = protocol_1.default.Response.fromBase64(chatlist[i]);
                    }
                    catch (e) {
                        log_1.default.error('~~~~~history  解析失败，当前原始数据 info:' + e);
                        log_1.default.error(data[i]);
                    }
                }
            }
            _suc(res);
        };
        options.error = function (e) {
            _error && _error(e);
            analytics_1.default.report({
                nm: 'message_kefu_sessionlist_error',
                val: {
                    code: e && e.request && e.request.status ? e.request.status : void 0
                }
            });
        };
        this.request(url, options);
    },
    /**
     * 获取消息附属信息
     * @param url 获取的url
     * @param options 获取参数
     * @private
     */
    _messageAddition: function (url, options, fromSource) {
        if (url === void 0) { url = ''; }
        var _suc = options.success;
        var _error = options.error;
        options.success = function (res) {
            if (res.rescode === 0) {
                var additionsList = res.data ? res.data.additions : [];
                if (additionsList && additionsList.length) {
                    for (var i = 0; i < additionsList.length; i++) {
                        try {
                            additionsList[i] = protocol_1.default.Response.fromBase64(additionsList[i].body, 2);
                        }
                        catch (e) {
                            log_1.default.error('_messageAddition 解析失败 info:' + e + ' additionData:' + additionsList[i]);
                        }
                    }
                }
            }
            _suc(res);
        };
        options.error = function (e) {
            _error && _error(e);
        };
        this.request(url, options);
    }
};


//# sourceURL=webpack://MTDX/./src/core/http/http.core.ts?